﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Assumes.cs" company="AzureContrib (Open source library http://azurecontrib.codeplex.com)">
//   Microsoft Public License (Ms-PL)
// </copyright>
// <summary>
//   Helper class for checking parameters in method calls
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Diagnostics;

namespace AzureContrib.WindowsAzure
{
	/// <summary>
	/// Helper class for checking parameters in method calls
	/// </summary>
	public static class Assumes
	{
		/// <summary>
		/// Checks that a parameter is not null or throws an <see cref="ArgumentNullException"/>
		/// </summary>
		/// <typeparam name="T">The type of the value that is not null.</typeparam>
		/// <param name="value">The value.</param>
		/// <param name="parameterName">The param Name.</param>
		/// <exception cref="ArgumentNullException">if the <paramref name="value"/> is null.</exception>
		[DebuggerStepThrough]
		public static void NotNull<T>(T value, string parameterName)
			where T : class
		{
			if (value == null)
			{
				throw new ArgumentNullException(parameterName);
			}
		}

		/// <summary>
		/// The <paramref name="value"/> is not a null or empty <see cref="string"/>.
		/// </summary>
		/// <param name="value">The value to check</param>
		/// <param name="parameterName">The name of the parameter used to supply the value.</param>
		/// <param name="message">The failure message to use should the value be null or empty.</param>
		[DebuggerStepThrough]
		public static void NotNullOrEmpty(string value, string parameterName, string message)
		{
			if (string.IsNullOrEmpty(value))
			{
				throw new ArgumentOutOfRangeException(parameterName, message);
			}
		}
	}
}